import { PartialType } from '@nestjs/mapped-types';
import { CreateCommunityDto } from './create-community.dto';
import { ApiProperty } from '@nestjs/swagger';
import {
  IsArray,
  IsNotEmpty,
  IsOptional,
  IsString,
  MaxLength,
  MinLength,
  ValidateNested,
} from 'class-validator';
import { Goods } from 'src/goods/entities/goods.entity';
import { Type } from 'class-transformer';
import { User } from 'src/user/entities/user.entity';

export class UpdateCommunityDto extends PartialType(CreateCommunityDto) {
  @ApiProperty({ description: '社区名称' })
  @IsNotEmpty()
  @IsString()
  @MinLength(2)
  @MaxLength(100)
  name: string;

  @ApiProperty({ description: '社区描述' })
  @IsOptional()
  @IsString()
  @MaxLength(200)
  description: string;

  @ApiProperty({ description: '社区位置' })
  @IsOptional()
  @IsString()
  @MaxLength(200)
  location: string;

  @ApiProperty({ description: '社区图片' })
  @IsOptional()
  @IsString()
  @MaxLength(200)
  image: string;

  @ApiProperty({ description: '社区用户' })
  @IsOptional()
  @IsArray()
  @ValidateNested()
  @Type(() => User)
  users: User[];

  @ApiProperty({ description: '社区商品' })
  @IsOptional()
  @IsArray()
  @ValidateNested()
  @Type(() => Goods)
  goods: Goods[];
}
